package moonlit.chill.pay.asyncFactory.service.impl;

import lombok.extern.slf4j.Slf4j;
import moonlit.chill.pay.asyncFactory.service.AsyncTaskService;
import moonlit.chill.pay.cache.WaitingPayCache;
import moonlit.chill.pay.vo.PayResult;
import moonlit.chill.pay.vo.PaySearchParam;
import moonlit.chill.pay.vo.PaySearchRule;
import moonlit.chill.pay.vo.TradeParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author MoonlitChill
 * @date 2024/4/24 16:10
 */
@Slf4j
@Service
public class AsyncTaskServiceImpl implements AsyncTaskService {

    @Autowired
    private WaitingPayCache waitingPayCache;

    @Override
    public void payQuerySuccess(PayResult<?> result, TradeParam tradeParam) {
        //TODO 具体业务
        log.info("查询到用户支付成功");
    }

    @Override
    public void launchPaySuccessHandle(PayResult<?> result, TradeParam tradeParam) {
        PaySearchParam param = new PaySearchParam();
        param.setStartTime(System.currentTimeMillis());
        param.setPaySearchRule(PaySearchRule.LEVEL_1);
        tradeParam.setSearchParam(param);
        waitingPayCache.offer(tradeParam, System.currentTimeMillis() + PaySearchRule.LEVEL_1.getIntervalTime() * 1000L);
        //TODO 具体业务
        log.info("发起支付成功");
    }
}
